/*
图片选择器选后图片显示
包含图片和右上角删除按钮
*/

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_ahj_app/base/utils/ShowFiles/GetFilesPath.dart';
import 'package:flutter_ahj_app/base/utils/ShowFiles/GetImageWidget.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';

class ImagePicked extends StatefulWidget {
  final String imageUrl;
  final int index;
  final ValueChanged<int> valueChanged;
  final String path;
  final String type;
  final String closeState;
  final BoxFit boxFit;
  ImagePicked(
      {this.imageUrl,
      this.index,
      this.valueChanged,
      this.path,
      this.type,
      this.closeState,
      this.boxFit,
      Key key})
      : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyAppState();
  }
}

class _MyAppState extends State<ImagePicked> {
  // VideoPlayerController _controller;
  String filePath;
  @override
  void initState() {
    super.initState();
    print("ImagePicked__data::" + widget.imageUrl);
  }

  @override
  Widget build(BuildContext context) {
    return new Stack(
      alignment: Alignment(0.92, -0.92),
      children: <Widget>[
        new ImageWidget(
                key: UniqueKey(),
                fileName: widget.imageUrl,
                width: (MediaQuery.of(context).size.width - 32.0 - 8.0) / 4,
                height: (MediaQuery.of(context).size.width - 32.0 - 8.0) / 4,
                boxFit: widget.boxFit,
              ),
        /*
        (widget.imageUrl!=null&&widget.imageUrl.startsWith("http"))?new Image.network(widget.imageUrl,width:(MediaQuery.of(context).size.width - 32.0 - 8.0) / 4 ,height: (MediaQuery.of(context).size.width - 32.0 - 8.0) / 4,):
        new Image.file(new File(widget.imageUrl),width:(MediaQuery.of(context).size.width - 32.0 - 8.0) / 4 ,height: (MediaQuery.of(context).size.width - 32.0 - 8.0) / 4,),*/
        "1" == widget.closeState
            ? new Container()
            : new GestureDetector(
                onTap: _handleCancel,
                child: new Container(
                  decoration: new BoxDecoration(
                    color: Colors.black45,
                    shape: BoxShape.circle,
                  ),
                  child: new Icon(
                    Icons.close,
                    color: Colors.white,
                    size: 20.0,
                  ),
                ),
              )
      ],
    );
  }

  void _handleCancel() {
    widget.valueChanged(widget.index);
    setState(() {});
  }

  @override
  void dispose() {
    super.dispose();
    // _controller?.dispose();
  }
}
